package com.yingcheng.numerology.framework.bazi.core.enums;

import cn.hutool.core.util.ArrayUtil;
import java.util.Arrays;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * 六十甲子表
 * <br>
 * [甲子, 乙丑, 丙寅, 丁卯, 戊辰, 己巳, 庚午, 辛未, 壬申, 癸酉,甲戌, 乙亥,
 * <br>
 * 丙子, 丁丑, 戊寅, 己卯, 庚辰, 辛巳, 壬午, 癸未,甲申, 乙酉, 丙戌, 丁亥,
 * <br>
 * 戊子, 己丑, 庚寅, 辛卯, 壬辰, 癸巳,甲午, 乙未, 丙申, 丁酉, 戊戌, 己亥,
 * <br>
 * 庚子, 辛丑, 壬寅,癸卯,甲辰, 乙巳, 丙午, 丁未, 戊申, 己酉, 庚戌, 辛亥,
 * <br>
 * 壬子, 癸丑,甲寅, 乙卯, 丙辰, 丁巳, 戊午, 己未, 庚申, 辛酉, 壬戌, 癸亥]
 *
 * @author xiaofeng
 * @date 2024/11/7 16:09
 */
@Getter
@RequiredArgsConstructor
public enum StemsAndBranchesTableEnum implements FieldEnumerable<StemsAndBranchesTableEnum> {


    JIA_ZI("甲子", "jia_zi", HeavenlyStemsEnum.JIA, EarthlyBranchesEnum.ZI, 1),
    YI_CHOU("乙丑", "yi_chou", HeavenlyStemsEnum.YI, EarthlyBranchesEnum.CHOU, 2),
    BING_YIN("丙寅", "bing_yin", HeavenlyStemsEnum.BING, EarthlyBranchesEnum.YIN, 3),
    DING_MAO("丁卯", "ding_mao", HeavenlyStemsEnum.DING, EarthlyBranchesEnum.MAO, 4),
    WU_CHEN("戊辰", "wu_chen", HeavenlyStemsEnum.WU, EarthlyBranchesEnum.CHEN, 5),
    JI_SI("己巳", "ji_si", HeavenlyStemsEnum.JI, EarthlyBranchesEnum.SI, 6),
    GENG_WU("庚午", "geng_wu", HeavenlyStemsEnum.GENG, EarthlyBranchesEnum.WU, 7),
    XIN_WEI("辛未", "xin_wei", HeavenlyStemsEnum.XIN, EarthlyBranchesEnum.WEI, 8),
    REN_SHEN("壬申", "ren_shen", HeavenlyStemsEnum.REN, EarthlyBranchesEnum.SHEN, 9),
    GUI_YOU("癸酉", "gui_you", HeavenlyStemsEnum.GUI, EarthlyBranchesEnum.YOU, 10),
    JIA_XU("甲戌", "jia_xu", HeavenlyStemsEnum.JIA, EarthlyBranchesEnum.XU, 11),
    YI_HAI("乙亥", "yi_hai", HeavenlyStemsEnum.YI, EarthlyBranchesEnum.HAI, 12),

    BING_ZI("丙子", "bing_zi", HeavenlyStemsEnum.BING, EarthlyBranchesEnum.ZI, 13),
    DING_CHOU("丁丑", "ding_chou", HeavenlyStemsEnum.DING, EarthlyBranchesEnum.CHOU, 14),
    WU_YIN("戊寅", "wu_yin", HeavenlyStemsEnum.WU, EarthlyBranchesEnum.YIN, 15),
    JI_MAO("己卯", "ji_mao", HeavenlyStemsEnum.JI, EarthlyBranchesEnum.MAO, 16),
    GENG_CHEN("庚辰", "geng_chen", HeavenlyStemsEnum.GENG, EarthlyBranchesEnum.CHEN, 17),
    XIN_SI("辛巳", "xin_si", HeavenlyStemsEnum.XIN, EarthlyBranchesEnum.SI, 18),
    REN_WU("壬午", "ren_wu", HeavenlyStemsEnum.REN, EarthlyBranchesEnum.WU, 19),
    GUI_WEI("癸未", "gui_wei", HeavenlyStemsEnum.GUI, EarthlyBranchesEnum.WEI, 20),
    JIA_SHEN("甲申", "jia_shen", HeavenlyStemsEnum.JIA, EarthlyBranchesEnum.SHEN, 21),
    YI_YOU("乙酉", "yi_you", HeavenlyStemsEnum.YI, EarthlyBranchesEnum.YOU, 22),
    BING_XU("丙戌", "bing_xu", HeavenlyStemsEnum.BING, EarthlyBranchesEnum.XU, 23),
    DING_HAI("丁亥", "ding_hai", HeavenlyStemsEnum.DING, EarthlyBranchesEnum.HAI, 24),

    WU_ZI("戊子", "wu_zi", HeavenlyStemsEnum.WU, EarthlyBranchesEnum.ZI, 25),
    JI_CHOU("己丑", "ji_chou", HeavenlyStemsEnum.JI, EarthlyBranchesEnum.CHOU, 26),
    GENG_YIN("庚寅", "geng_yin", HeavenlyStemsEnum.GENG, EarthlyBranchesEnum.YIN, 27),
    XIN_MAO("辛卯", "xin_mao", HeavenlyStemsEnum.XIN, EarthlyBranchesEnum.MAO, 28),
    REN_CHEN("壬辰", "ren_chen", HeavenlyStemsEnum.REN, EarthlyBranchesEnum.CHEN, 29),
    GUI_SI("癸巳", "gui_si", HeavenlyStemsEnum.GUI, EarthlyBranchesEnum.SI, 30),
    JIA_WU("甲午", "jia_wu", HeavenlyStemsEnum.JIA, EarthlyBranchesEnum.WU, 31),
    YI_WEI("乙未", "yi_wei", HeavenlyStemsEnum.YI, EarthlyBranchesEnum.WEI, 32),
    BING_SHEN("丙申", "bing_shen", HeavenlyStemsEnum.BING, EarthlyBranchesEnum.SHEN, 33),
    DING_YOU("丁酉", "ding_shou", HeavenlyStemsEnum.DING, EarthlyBranchesEnum.YOU, 34),
    WU_XU("戊戌", "wu_xu", HeavenlyStemsEnum.WU, EarthlyBranchesEnum.XU, 35),
    JI_HAI("己亥", "ji_hai", HeavenlyStemsEnum.JI, EarthlyBranchesEnum.HAI, 36),

    GENG_JI("庚子", "geng_ji", HeavenlyStemsEnum.GENG, EarthlyBranchesEnum.ZI, 37),
    XIN_CHOU("辛丑", "xin_chou", HeavenlyStemsEnum.XIN, EarthlyBranchesEnum.CHOU, 38),
    REN_YIN("壬寅", "ren_yin", HeavenlyStemsEnum.REN, EarthlyBranchesEnum.YIN, 39),
    GUI_MAO("癸卯", "gui_mao", HeavenlyStemsEnum.GUI, EarthlyBranchesEnum.MAO, 40),
    JIA_CHEN("甲辰", "jia_chen", HeavenlyStemsEnum.JIA, EarthlyBranchesEnum.CHEN, 41),
    YI_SI("乙巳", "yi_si", HeavenlyStemsEnum.YI, EarthlyBranchesEnum.SI, 42),
    BING_WU("丙午", "bing_wu", HeavenlyStemsEnum.BING, EarthlyBranchesEnum.WU, 43),
    DING_WEI("丁未", "ding_wei", HeavenlyStemsEnum.DING, EarthlyBranchesEnum.WEI, 44),
    WU_SHEN("戊申", "wu_shen", HeavenlyStemsEnum.WU, EarthlyBranchesEnum.SHEN, 45),
    JI_YOU("己酉", "ji_you", HeavenlyStemsEnum.JI, EarthlyBranchesEnum.YOU, 46),
    GENG_XU("庚戌", "geng_xu", HeavenlyStemsEnum.GENG, EarthlyBranchesEnum.XU, 47),
    XIN_HAI("辛亥", "xin_hai", HeavenlyStemsEnum.XIN, EarthlyBranchesEnum.HAI, 48),

    REN_ZI("壬子", "ren_zi", HeavenlyStemsEnum.REN, EarthlyBranchesEnum.ZI, 49),
    GUI_CHOU("癸丑", "gui_chou", HeavenlyStemsEnum.GUI, EarthlyBranchesEnum.CHOU, 50),
    JIA_YIN("甲寅", "jia_yin", HeavenlyStemsEnum.JIA, EarthlyBranchesEnum.YIN, 51),
    YI_MAO("乙卯", "yi_mao", HeavenlyStemsEnum.YI, EarthlyBranchesEnum.MAO, 52),
    BING_CHEN("丙辰", "bing_chen", HeavenlyStemsEnum.BING, EarthlyBranchesEnum.CHEN, 53),
    DING_SI("丁巳", "ding_si", HeavenlyStemsEnum.DING, EarthlyBranchesEnum.SI, 54),
    WU_WU("戊午", "wu_wu", HeavenlyStemsEnum.WU, EarthlyBranchesEnum.WU, 55),
    JI_WEI("己未", "ji_wei", HeavenlyStemsEnum.JI, EarthlyBranchesEnum.WEI, 56),
    GENG_SHEN("庚申", "geng_shen", HeavenlyStemsEnum.GENG, EarthlyBranchesEnum.SHEN, 57),
    XIN_YOU("辛酉", "xin_you", HeavenlyStemsEnum.XIN, EarthlyBranchesEnum.YOU, 58),
    REN_XU("壬戌", "ren_xu", HeavenlyStemsEnum.REN, EarthlyBranchesEnum.XU, 59),
    GUI_HAI("癸亥", "gui_hai", HeavenlyStemsEnum.GUI, EarthlyBranchesEnum.HAI, 60);


    public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(StemsAndBranchesTableEnum::getIndex).toArray();
    private final String name;
    private final String code;
    private final HeavenlyStemsEnum heavenlyStemsEnum;
    private final EarthlyBranchesEnum earthlyBranchesEnum;
    private final Integer index;

    public static StemsAndBranchesTableEnum getByIndex(final Integer index) {
        return ArrayUtil.firstMatch(stemsAndBranchesTableEnum -> stemsAndBranchesTableEnum.getIndex().equals(index),
                values());
    }

}
